/*LICENSE_BEGIN
 * ******************************************************************
 * All original parts of SoccerScope2003 have copyright (2003) by
 * Team YowAI, represented by Mr. Shuhei Shiota
 * The Department of Creative Informatics
 * The Graduate School of Information Science and Technology
 * The University of Tokyo
 * 
 * Additional classes (except libraries in /lib) were developed by 
 * the Dainamite Robocup-Team of the DAI-Labor, TU-Berlin 
 * (www.dai-labor.de)
 * 
 * Extended/new classes/packages are:
 *   soccerscope.analyzer.LogfileAnalyzer
 *   soccerscope.daistatistic.*
 *   soccerscope.daistatistic.charts.*
 *   soccerscope.daistatistic.tools.*
 *   soccerscope.db.*
 *   soccerscope.dialog.*
 *   soccerscope.model.PlayerWorldModel
 *   soccerscope.model.SimplePlayer
 *   soccerscope.net.AgentConnector
 *   soccerscope.training.*
 *   soccerscope.training.conditions.*
 * ******************************************************************
LICENSE_END*/
package soccerscope.view.layer;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

import soccerscope.model.Param;
import soccerscope.model.PlayerWorldModel;
import soccerscope.model.SoccerObjectID;
import soccerscope.util.geom.Point2f;
import soccerscope.view.FieldPane;
import soccerscope.view.SoccerObjectSelectObserver;

public class MarkOpponentLayer extends Layer implements
				SoccerObjectSelectObserver, SoccerObjectID {

	
	private Point2f center = new Point2f(0, 0);

	private float radius = 0;

	private Point2f from = new Point2f(0, 0);
	
	private boolean[] isSelected = new boolean[Param.MAX_PLAYER];
	
	private int oppNum = 1;
	
	
	public MarkOpponentLayer(FieldPane fieldPane, boolean enable) {
		super(fieldPane, enable);
	}

	@Override
	public String getLayerName() {
		return "MarkOpponentArea";
	}
	
	@Override
	public void draw(Graphics g) {
		if (!this.enable)
			return;

		for (int i = 0; i < Param.MAX_PLAYER; i++) {
            PlayerWorldModel pwm = this.fieldPane.getScene().player[i].getWorldModel();
			if (this.isSelected[i] && pwm != null && pwm.shouldMark) {
				if (pwm.oppNum != -1)
					oppNum = pwm.oppNum;
				if (pwm.markAreaX != -9999)
					center.y = (float)pwm.markAreaX;
				if (pwm.markAreaY != -9999)
					center.x = (float)pwm.markAreaY;
				if (pwm.markAreaRad != -9999)
					radius = (float)pwm.markAreaRad;
				if (pwm.opponents[oppNum-1].positionX != -9999)
					from.y = (float) pwm.opponents[oppNum-1].positionX;
				if (pwm.opponents[oppNum-1].positionY != -9999)
					from.x = (float) pwm.opponents[oppNum-1].positionY;
			
				((Graphics2D) g).setComposite(AlphaComposite.getInstance(
						AlphaComposite.SRC_OVER, 0.05f));
				g.setColor(Color.white);
				fillCircle(g, center, radius);
				((Graphics2D) g).setComposite(AlphaComposite.getInstance(
						AlphaComposite.SRC_OVER, 1.0f));
				g.setColor(Color.red);
				drawArrow(g, from, center);
			}
		}
	}
	
	
	public void selectSoccerObject(int id, boolean flag) {
		if (id > 10) {
			return;
		}
		this.isSelected[id] = flag;
	}
}
